package com.babel.util.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class HandelRequest {
    /**
     * 得到所有的参数的值
     * @param request
     * @return
     */
    public static Map<String,Object> handelRequest(HttpServletRequest request){
        Map<String,Object> obj = new HashMap<String,Object>();
        Enumeration<String> coll =  request.getParameterNames();
        while(coll.hasMoreElements()){
            String key = coll.nextElement();
            obj.put(key,  request.getParameter(key)==null?"":request.getParameter(key) );
        }
        if(obj.get("pageNumber")!=null){
            int pageSize = 10; //Integer.valueOf(obj.get("pageSize").toString());
            int pageNumber = Integer.valueOf(obj.get("pageNumber")==null ? "10" : obj.get("pageNumber").toString());
            int startIndex = (pageNumber - 1) * pageSize;
            obj.put("startIndex", startIndex);
            obj.put("pageSize", 10);
            obj.put("pageNumber", pageNumber);
        }
        return obj;
    }
}
